package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @create: 2024/9/11
 * @author: gyhe10
 * @description: 封装订单确认页需要的数据
 **/

public class OrderConfirmVo {

    /**
     * 收货地址列表
     */
    @Getter
    @Setter
    private List<MemberAddressVo> address;

    /**
     * 购物车选中商品列表
     */
    @Getter
    @Setter
    private List<OrderItemVo> items;

    public Integer getCount() {
        Integer count = 0;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    /**
     * 发票信息，暂未实现
     */

    /**
     * 优惠券信息，暂未实现，只显示会员积分信息
     */
    @Getter
    @Setter
    private Integer integration;

    @Getter
    @Setter
    private Map<Long, Boolean> stocks;

    /**
     * 订单令牌，防止重复提交
     */
    @Getter
    @Setter
    private String orderToken;

    /**
     * 订单总额
     */
    private BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal(0);
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    /**
     * 应付价格
     */
    private BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal(0);
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }
}
